<template>
  <div id="InspectionDilapidated" :class="{smallFontSize:showEdition,mediumFontSize:!showEdition}">
    <div v-if="isShow" style="height: 100vh;overflow-y: auto">
      <div>
        <form action="/">
          <van-search
            style="
           width: calc(100% - 4px);
           background: #EEE;
           border-radius: 10px;
           height:40px;
           font-size: 14px;
           float: left"
            v-model="SearchData"
            placeholder="请输入信息"
            @search="onSearch"
          />
        </form>
      </div>
      <div>
        <van-list  >
          <van-cell v-for="(item, index) in contentData" @click="contentClick(item)" :key="index">
            <ul>
              <li>
                <p style="margin-bottom: 8px; height: 3vh">
                  <span style="font-weight: bold;">{{ item.propertyPerson }}</span>
                  <span style="float: right">
                     <span style="float: right">房屋类别：{{ item.houseType }}</span>
                  </span>
                </p>
                <p style="clear: both; display: flex; align-items: center">
                  <img
                    style="margin-right: 4px"
                    width="10"
                    src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/YPC/dingwei.png"
                  />
                  <span @click="gotoMap(item)" style="font-size: 14px; color: blue">
                  {{ item.belongCity}}{{ item.belongCountry}}{{ item.belongTown}}{{ item.belongVillage}}
                </span>
                </p>
              </li>
            </ul>
          </van-cell>
        </van-list>
      </div>
    </div>
    <div v-if="!isShow">
      <div style="height: 84vh;overflow:auto;">
        <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">巡查信息</p>
        <van-field  v-model="fromData.patrolPerson" label="巡查人" />
        <van-field  v-model="fromData.patrolDate" label="巡查时间" />
        <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">房屋用途</p>
        <van-field readonly clickable name="picker" v-model="FWYTNH" label="房屋用途变化" placeholder="请选择"
                   @click="showPicker = true" />
        <van-popup v-model="showPicker" position="bottom" get-container="#popup">
          <van-picker value-key="name" show-toolbar :columns="columns" @confirm="onConfirm"
                       @cancel="showPicker = false" />
        </van-popup>
        <van-field readonly clickable name="picker" v-model="FWYT" label="房屋用途" placeholder="请选择"
                   @click="showPicker1 = true" />
        <van-popup v-model="showPicker1" position="bottom" get-container="#popup">
          <van-picker value-key="name" show-toolbar :columns="columns1" @confirm="onConfirm1"
                      @cancel="showPicker1 = false" />
        </van-popup>
        <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">改扩建情况</p>
        <van-field readonly clickable name="picker" v-model="SFGKJ" label="是否改扩建" placeholder="请选择"
                   @click="showPicker2 = true" />
        <van-popup v-model="showPicker2" position="bottom" get-container="#popup">
          <van-picker value-key="name" show-toolbar :columns="columns" @confirm="onConfirm2"
                      @cancel="showPicker2 = false" />
        </van-popup>
        <van-field  v-model="fromData.expansionContent" label="改扩建内容" />
        <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">现场状况</p>
        <van-field name="radio" v-for="(item,index) in XCZKData" :key="index" :label="item.name">
          <template #input>
            <van-radio-group v-model="fromData[item.prop]" direction="horizontal">
              <van-radio :name=1>是</van-radio>
              <van-radio :name=0>否</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="fromData.otherProblem"
          rows="3"
          autosize
          label="其他问题"
          type="textarea"
          placeholder="请输入其他问题"
        />
        <van-field   name="uploader" label="巡查照片">
          <template #input>
            <van-uploader
              ref="uploadFile"
              :after-read="afterRead"
              :before-delete="delectFile"
              v-model="fileList"
            />
          </template>
        </van-field>
        <p style="width: 100%;text-align: center;font-weight: bold;padding: 10px;">初步判定</p>
        <van-field name="radio"  label="初步判定">
          <template #input>
            <van-radio-group v-model="fromData.firstJudge" direction="horizontal">
              <van-radio :name=0>基本安全</van-radio>
              <van-radio :name=1>存在风险</van-radio>
            </van-radio-group>
          </template>
        </van-field>
      </div>
      <div class="footer">
        <van-button  style="width: 40%;" :style="{fontSize:showEdition?'14px':'20px'}"  type="info" @click="saveData()">保存</van-button>
        <van-button  style="width: 40%;" :style="{fontSize:showEdition?'14px':'20px'}"  type="info" @click="saveData('submit')">提交</van-button>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
  export default {
    name: "InspectionDilapidated",
    data() {
      return{
        FWYTNH:'',
        FWYT:'',
        SFGKJ:'',
        XCZKData:[
          {
            name:'受重大工程施工影响',
            prop:"zdgcyx"
          },
          {
            name:'周边山体边坡塌陷',
            prop:"zbsttx"
          },
          {
            name:'房屋倾斜、局部倒塌',
            prop:"fwqx"
          },
          {
            name:'墙体拆除、歪斜',
            prop:"qtcc"
          },
          {
            name:'梁板柱拆除、歪斜',
            prop:"lbzcc"
          },
          {
            name:'钢筋裸露、锈蚀',
            prop:"gjlu"
          },
          {
            name:'防控危房有人居住',
            prop:"fkwfyrjz"
          },
        ],
        fromData: {
          "expansionContent": "",
          "fileGroupId": "",
          "firstJudge": "",
          "fkwfyrjz": "",
          "fwqx": "",
          "gjlu": "",
          "houseUsage": "",
          "id": "",
          "isExpansion": "",
          "isHouseUsageChange": "",
          "lbzcc": "",
          "objectNo": "",
          "otherProblem": "",
          "patrolDate": "",
          "patrolPerson": "",
          "qtcc": "",
          "zbsttx": "",
          "zdgcyx": "",
        },
        KNJTuserType:'',
        userType:'',
        isLongData:false,
        JDJGData:"",
        value:false,
        KNJTform: {
          remark: '',
          userType: '',
          objectNo: ''
        },
        JBXXform: {
          objectNo: '',
          userName: "",  // 处理人名称
          userId: "",  // 处理人id
          isAuth: '',
          authLevel: '',
          authCompanyName: '',
          socialCreditCode: '',
          recheck:0,
          isFarmHouse: '',
          fileHousePicture: ''
        },
        SearchData:'',
        showEdition: false,
        loading: false,
        finished: false,
        contentData:[],
        isShow:true,
        showPicker:false,
        showPicker1:false,
        showPicker2:false,
        showPicker3:false,
        columns:[
          {
            name:'是',
            value:1
          },
          {
            name:'否',
            value:0
          }
          ],
        columns1:[
          {
            name:'经营性自建房',
            value:1
          },
          {
            name:'其他自建房',
            value:2
          }
        ],
        formData:{
          ZLFS:'',
          BLR:'',
          BLSJ:""
        },
        showPickerq:false,
        currentDate: new Date(),
        formArry:[
          {
            name:'姓名',
            prop:'XM'
          },
          {
            name:'身份证号',
            prop:'XM'
          },
          {
            name:'性别',
            prop:'XM'
          },
          {
            name:'出生年月',
            prop:'XM'
          },
          {
            name:'联系电话',
            prop:'XM'
          },
          {
            name:'证书编号',
            prop:'XM'
          },
          {
            name:'技能',
            prop:'XM'
          },
          {
            name:'文化程度',
            prop:'XM'
          },
          {
            name:'常住地址',
            prop:'XM'
          },
          {
            name:'从业年限(仅限数字)',
            prop:'XM'
          },
        ],
        fileList:[],
        BaseURL:window.g.BaseURL,
        rowData:""
      }
    },
    methods:{
      //上传附件
      afterRead: async function (file) {
        console.log(file)
        // console.log(this.fileList)
        var formData = new FormData();
        formData.append("files", file.file);
        formData.append('path', 'wg')
        formData.append("groupName", "巡查照片");
        formData.append("toGroupGuid", this.groupGuid);
        let webResult = await axios.post(this.BaseURL + '/api/upload/oss/files', formData, {
          headers: {
            isOutParam: true,
          },
        });
        console.log(webResult)
        if (webResult.data && webResult.data.data) {
          this.fromData.fileGroupId = this.groupGuid
          file.id = webResult.data.data[0].id
          this.$message.success("上传成功")
        } else {
          file.status = 'failed';
          file.message = '上传失败';
        }
      },
      //删除附件
      delectFile:async function(file, fileList) {
        console.log(file, fileList)
        let arr = [];
        arr.push(file.id)
        let webResult = await axios.post(this.BaseURL + 'api/upload/oss/delete', arr, {
          headers: {
            isOutParam: true,
            isOutParamS: true,
          },
        });
        if (webResult.data.data) {
          // this.uploadlist.forEach(item => {
          this.fileList.forEach((items, index) => {
            if (items.id == file.id) {
              this.fileList.splice(index, 1)
            }
          })
          // })
          this.$message.success(webResult.data.msg)
        } else {
          this.$message.error(webResult.data.msg)
        }
      },
      WXJDChange() {

      },
      onSearch(){
this.getData()
      },
      contentClick(item){
        this.isShow = false
        this.rowData = item

        this.getJDXXList()
      },
      onConfirmRQ(){

      },
      getData: async function() {
        // let parm1 = {
        //   "belongCountryList": [],
        //   "belongCountyList": [],
        //   "name": "",
        //   "pageNo": 1,
        //   "pageSize": 100000
        // }
        // let webResult1 = await axios.post(this.BaseURL + '/api/farmerHouse/zhejiangHouseTechnicalUnit/selectTechnicalList', parm1, {
        //   headers: {
        //     isOutParam: true,
        //   },
        // });
        // this.JDJGData = webResult1.data.data.pageList
        // let parm = {
        //   cityCode: "33",
        //   pageNo: 1,
        //   pageSize: 100000,
        //   propertyPerson:this.SearchData
        // }
        // let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseRemold/list', parm, {
        //   headers: {
        //     isOutParam: true,
        //   },
        // });
        // console.log(webResult)
        // this.contentData = webResult.data.data.pageList
        let parm = {
          pageNo: 1,
          pageSize: 100,
          cityCode: window.localStorage.getItem('citycode').replace(/(0+)$/g, ""),
          patrolProcessNode: 0,
          propertyPerson:this.SearchData,
        }
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/housePatrol/patrolList', parm, {
          headers: {
            isOutParam: true,
          },
        });
        this.contentData = webResult.data.data.pageList
      },
      onConfirm(data) {
        this.fromData.isHouseUsageChange = data.value
        this.FWYTNH = data.name
        this.showPicker = false
      },
      onConfirm1(data) {
        this.fromData.houseUsage = data.value
        this.FWYT = data.name
        this.showPicker1 = false
      },
      onConfirm2(data){
        this.fromData.isExpansion = data.value
        this.SFGKJ = data.name
        this.showPicker2 = false
      },
      JDJGChange(data) {
        this.JBXXform.authCompanyName = data.qymc
        this.JDJGData.forEach(item=>{
          if (item.qymc == data.qymc) {
            this.JBXXform.socialCreditCode = item.zzjgdm
          }
        })
        this.showPicker3 = false
      },
      //信息回显
      getJDXXList: async function() {
        // let parm = {
        //   "objectNo": this.rowData.objectNo,
        //   "recheck": "0"
        // }
        // let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/dangerHouseRemold/authInfo', parm, {
        //   headers: {
        //     isOutParam: true,
        //   },
        // });
        // console.log(webResult)
        // if(webResult.data){
        //   this.JBXXform.isFarmHouse = webResult.data.isFarmHouse
        //   if (webResult.data.fileHousePicture) {
        //     this.groupGuid = webResult.data.fileHousePicture
        //   }
        //   if (webResult.data.fileHousePictureUrlList) {
        //     webResult.data.fileHousePictureUrlList.forEach((item)=>{
        //       this.fileList.push({
        //         id: item.id,
        //         url: this.BaseURL + "api/upload/oss/preview?fileId=" + item.id,
        //         name: item.fileName,
        //       })
        //     })
        //   }
        //   if(webResult.data.companyName){
        //     this.JBXXform.authCompanyName = webResult.data.companyName;
        //     this.JBXXform.socialCreditCode = webResult.data.companyUscc;
        //     this.JBXXform.isAuth='否'
        //   }else{
        //
        //     this.JBXXform.isAuth='是'
        //     this.JBXXform.authLevel = "D"
        //   }
        // }
        if (this.rowData.objectNo) {
          let parm = {
            objectNo: this.rowData.objectNo
          }
          let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/housePatrol/getPatrolDetailInfo', parm, {
            headers: {
              isOutParam: true,
            },
          });
          if (webResult.data.data) {
            for (var i in this.fromData) {
              for (var k in webResult.data.data) {
                if (i == k) {
                  this.fromData[i] = webResult.data.data[k]
                }
              }
            }
            this.FWYTNH = this.fromData.isHouseUsageChange=='1'?'是':'否'
            this.FWYT = this.fromData.houseUsage=='1'?'经营性自建房':'其他自建房'
            this.SFGKJ = this.fromData.isExpansion=='1'?'是':'否'
            this.fromData.fileGroupId ? this.groupGuid = this.fromData.fileGroupId : "";
            webResult.data.data.fileGroupList.forEach(item => {
              // if (Eca.Config.priviewType == "2") {
                this.fileList.push({
                  id: item.id,
                  url: this.BaseURL + "api/upload/oss/preview?fileId=" + item.id,
                  name: item.fileName,
                })
              // } else {
              //   this.fileList.push({
              //     id: item.id,
              //     url: Eca.Config.ossBaseURL + "/" + item.fileUrl,
              //     name: item.fileName,
              //   })
              // }
            })
          }
        }
      },
      saveData: async function (type) {
        if(this.fromData.firstJudge===""){
          this.$message.error("排查结论不能为空!")
          return;
        }
        let parmData = this.fromData
        parmData['objectNo'] = this.rowData.objectNo;
        debugger
        parmData['fileGroupId'] = this.groupGuid;
        delete parmData.fileGroupList;
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/housePatrol/savePatrolInfo', parmData, {
          headers: {
            isOutParam: true,
          },
        });
        if (type == "submit") {
          this.submit()
        } else {
          if (webResult.data.data) {
            this.$message.success("保存成功")
          } else {
            this.$message.error("保存失败")
          }
        }
      },
      //提交
      submit: async function () {
        let parm = {
          objectNo: this.rowData.objectNo,
          // userName: "",
          // userId: ""
        }
        let webResult = await axios.post(this.BaseURL + '/api/farmerHouse/housePatrol/submitPatrolInfo', parm, {
          headers: {
            isOutParam: true,
          },
        });
        if (webResult.data.data) {
          this.$message.success("提交成功")
          this.backHomepage()
        } else {
          this.$message.error("提交失败")
        }
      },
      backHomepage() {
        this.getData()
        this.isShow = true
      },
    },
    mounted() {
      this.fromData.patrolPerson = JSON.parse(window.localStorage.getItem('userName')).loginName
      this.fromData.patrolDate = this.getDate()
      this.groupGuid = this.newGuid()
      this.showEdition = this.$store.state.Edition
      this.getData()

    }
  };
</script>

<style scoped lang="scss">
  #InspectionDilapidated{
    padding: 10px;
    text-align: center;
    .footer{
      width: 95%;
      position: fixed;
      bottom: 10px;
    }
  }
</style>
